package com.heclgg.eggcalculator.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.Toast
import com.heclgg.eggcalculator.R

/**
 * Dialog 封装类
 */
class MyDialog(context: Context, dialogView: Int) : Dialog(context, dialogView),
    View.OnClickListener {

    companion object {
        const val TAG = "MyDialog"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.test_dialog)
        val window = window
        val layoutParam = window!!.attributes
        layoutParam.width = this.context.resources.displayMetrics.widthPixels
        window.setGravity(Gravity.BOTTOM)

        findViewById<Button>(R.id.exit_button).setOnClickListener(this)
        findViewById<Button>(R.id.enter_button).setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        if (v == null)
            return

        when (v.id) {
            R.id.exit_button -> {
                Toast.makeText(context, "exit", Toast.LENGTH_SHORT).show()
                dismiss()
            }

            R.id.enter_button -> {
                Toast.makeText(context, "enter", Toast.LENGTH_SHORT).show()
                dismiss()
            }

            else -> dismiss()
        }
    }
}